<%-- 
    Document   : horarios
    Created on : 28-may-2012, 15:13:07
    Author     : Administrador
--%>
<%@page import="com.javabeans.Facultad"%>
<%@page import="com.javabeans.Horario"%>
<%@page import="com.javabeans.PeriodoDia"%>
<%@page import="com.javabeans.DiaSemana"%>

<%@include file="../../../../controlSession.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    List<DiaSemana> diasSemana = (List<DiaSemana>)request.getAttribute("diasSemana");
    List<PeriodoDia> periodosDia = (List<PeriodoDia>)request.getAttribute("periodosDia");
    List<Horario> horarios = (List<Horario>)request.getAttribute("horarios");
    Facultad facultad = (Facultad)request.getAttribute("Facultad");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>SI-ESFM </title>
        <meta name="description" content="Derechos Reservados SI-ESFM." />
        <link rel="stylesheet" href="<%=s_path%>/css/styles.css" type="text/css" />
        <link rel="stylesheet" href="<%=s_path%>/css/menu/style.css" type="text/css" />
        <link rel="shortcut icon" href="<%=s_path%>/images/ico.png" type="image/png"/>
        <script type="text/javascript" src="<%=s_path%>/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/comun.js"></script>
        <script type="text/javascript">
            function newP(idFacultad,nomFac){ // accion = 11 = nuevo periodo dia
                location.href = "Administracion?accion=3&idFacultad="+idFacultad+"&nomFac="+nomFac;
            }
            
            function edit(idDiaPeriodo,dias,idFacultad,nomFac){
                var sbody = "accion=5&idDiaPeriodo="+idDiaPeriodo+"&dias="+dias+"&idFacultad="+idFacultad+"&nomFac="+nomFac;
                location.href = "Administracion?"+sbody;
            }
        </script>
    </head>
    <body onload="showTime(<%=s_param%>)">
        <div id="top-wrap">
            <!-- cabeza principal -->
            <%@include file="../../../../head.jsp" %>
            
            <!-- cuerpo -->
            <div id="bodySpace">               
                <!-- aqui va la ruta -->
                <div class="clearfix" id="middle" style="position: absolute">
                    <!-- aqui va el arbol de entrada -->
                    <div id="breadcrumb"><!-- le da la forma de la imagen -->
                        <ul>
                            <li><a href="<%=s_path%>/principal.jsp">Home</a></li>
                            <li><span style="color:#666">Administraci&oacute;n</span></li>
                            <li><span style="color:#666">Administraci&oacute;n General</span></li>
                            <li class="current-page"><span class="end"><span class="middle">Horarios</span></span></li>
                        </ul>                        
                    </div><!-- begin SIDEBAR FIRST -->
                </div>
                <div id="principal">
                    <!-- izquierda -->
                    <div class="cuerpo2y" style="border: 0px solid"><br/><br/><!-- estos break son necesarios ya q uso absolute en css  cuerpo izquierdo-->
                        <div class="izq">
                            <%@include file="../../../../bodyIzq.jsp" %>
                        </div>
                        <div class="medio" style="border: 0px solid">
                            <h2 class="decorado">ADMINISTRACI&Oacute;N DE HORARIO DE LA UNIDAD ACADEMICA <br/><%=facultad.getNombre()%></h2>
                            <center>
                            <table class="miReporte" style="width: 100%">
                                <tr><td style="text-align: right"><input type="button" class="boton" value="A&ntilde;adir Periodo d&iacute;a" onclick="newP(<%=facultad.getIdFacultad()%>,'<%=facultad.getNombre()%>')"/></td></tr>
                            </table>
                            <table class="tabla_decorado" style="width: 100%">
                        <%
                            int i = 0;
                            int j = 0;
                            int idD = 0;
                            int idP = 0;
                            int sizeD = diasSemana.size();
                            boolean flag = false;
                            String dias;
                            if(periodosDia.size() > 0){
                                for(PeriodoDia pd : periodosDia){
                                    idP = pd.getIdPeriodoDia();
                                    if(i == 0){ %>
                                        <thead>
                                            <tr><!--  -->
                                                <th width="10%" class="th_decoradoRowspan">&nbsp;</th>
                                    <%
                                        for(DiaSemana ds : diasSemana){
                                            out.println("<th width='"+(80/sizeD)+"%' class='th_decoradoRowspan'>"+ds.getNombre()+"</th>");
                                        }
                                    %>      
                                                <th width="10%" class="th_decoradoRowspan">ACCI&Oacute;N</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                            <%          
                                    }
                                    j = 0;
                                    // tr_decoradoRowspan
                                    dias = "";
                                    out.println("<tr class='tr_decoradoRowspan'>");
                                    while(j < sizeD){
                                        if(j == 0)
                                            out.println("<td class='td_decoradoRowspan' align='center'>"+pd.getHoraIni()+" - "+pd.getHoraFin()+"</td>");
                                        DiaSemana ds = (DiaSemana)diasSemana.get(j);
                                        idD = ds.getIdDiaSemana();
                                        flag = false;
                                        for(Horario h : horarios){
                                            if(idD == h.getIdDiaSemana() && idP == h.getIdPeriodoDia()){
                                                flag = true;
                                                dias += idD+"_";
                                            }
                                        }
                                        out.println("<td class='td_decoradoRowspan' align='center' "+((flag)?"style='background:yellow'":"")+">&nbsp;</td>");
                                        j++;
                                    }
                                    if(dias.length() > 0){
                                        j = dias.lastIndexOf("_");
                                        dias = dias.substring(0,j);
                                    }
                                    out.println("<td class='td_decoradoRowspan' style='text-align:center'><input type='button' value='Editar' class='botonRep' onclick='edit("+idP+",\""+dias+"\","+facultad.getIdFacultad()+",\""+facultad.getNombre()+"\")'/></td>");                                    
                                    out.println("</tr>");
                                    i++;
                                } // fin for
                            }else{
                                out.println("<tr class='tr_decoradoRowspan'>");
                                out.println("   <td class='td_decoradoRowspan' style='text-align:center;color:red'>No existen periodos del d&iacute;a!</td>");
                                out.println("</tr>");
                            }
                        %>    
                                    </tbody>
                            </table>
                            </center>
                            
                            
                        </div>
                    </div><!--end of leftPan-->
                    
                    <div class="yDer" style="border: 1px solid #ccc;">
                        <%@include file="../../../../publicidad.jsp" %>                       
                    </div><!--end of rightPan-->
                </div><!--end of content-wrapper-->
            </div><!--end of body-wrap-->
            
            <!-- footer -->
        </div>
    </body>
</html>

